package proyecto;//GEN-FIRST:event_jButton6ActionPerformed
//GEN-LAST:event_jButton6ActionPerformed
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JOptionPane;

        
public class Memoria extends javax.swing.JFrame {

    public ImageIcon a1 = new ImageIcon("src/imagenes/memoriaimg/1.png");
    public ImageIcon a2 = new ImageIcon("src/imagenes/memoriaimg/2.png");
    public ImageIcon a3 = new ImageIcon("src/imagenes/memoriaimg/3.png");
    public ImageIcon a4 = new ImageIcon("src/imagenes/memoriaimg/4.png");
    public ImageIcon a5 = new ImageIcon("src/imagenes/memoriaimg/5.png");
    public ImageIcon a6 = new ImageIcon("src/imagenes/memoriaimg/6.png");
    public ImageIcon a7 = new ImageIcon("src/imagenes/memoriaimg/7.png");
    public ImageIcon a8 = new ImageIcon("src/imagenes/memoriaimg/8.png");
    public ImageIcon ganar = new ImageIcon("src/imagenes/memoriaimg/ganar.gif");
    public ImageIcon acertar = new ImageIcon("src/imagenes/memoriaimg/win.gif");
    public JButton btnact1 = null;
    public JButton btnact2 = null;
    int activos = 0;
    
    public Memoria() {
        this.setUndecorated(true);
        initComponents();
        this.setLocationRelativeTo(null);
        jButton17.setIcon(new ImageIcon("src/imagenes/memoriaimg/regresar.png"));
        jButton18.setIcon(new ImageIcon("src/imagenes/memoriaimg/jugar.png"));
        jButton1.setEnabled(false);
        jButton2.setEnabled(false);
        jButton3.setEnabled(false);
        jButton4.setEnabled(false);
        jButton5.setEnabled(false);
        jButton6.setEnabled(false);
        jButton7.setEnabled(false);
        jButton8.setEnabled(false);
        jButton9.setEnabled(false);
        jButton10.setEnabled(false);
        jButton11.setEnabled(false);
        jButton12.setEnabled(false);
        jButton13.setEnabled(false);
        jButton14.setEnabled(false);
        jButton15.setEnabled(false);
        jButton16.setEnabled(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    
    private int ca1=0,ca2=0,ca3=0,ca4=0,ca5=0,ca6=0,ca7=0,ca8=0,ca9=0,ca10=0,ca11=0,ca12=0,ca13=0,ca14=0,ca15=0,ca16=0, i=0;
    private int oc=0;
    int posimg1 = 0, posimg2 = 0, posimg3 = 0, posimg4 = 0, posimg5 = 0, posimg6 = 0, posimg7 = 0, posimg8 = 0,
        posimg9 = 0, posimg10 = 0, posimg11 = 0, posimg12 = 0, posimg13 = 0, posimg14 = 0, posimg15 = 0, posimg16 = 0;
    private int turno1 = 0, turno2 = 0;
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jButton17 = new javax.swing.JButton();
        jButton18 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        jButton11 = new javax.swing.JButton();
        jButton12 = new javax.swing.JButton();
        jButton13 = new javax.swing.JButton();
        jButton14 = new javax.swing.JButton();
        jButton15 = new javax.swing.JButton();
        jButton16 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(51, 51, 51));
        jPanel1.setForeground(new java.awt.Color(51, 51, 255));

        jPanel2.setBackground(new java.awt.Color(51, 51, 51));

        jButton17.setBackground(new java.awt.Color(19, 19, 19));
        jButton17.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton17ActionPerformed(evt);
            }
        });

        jButton18.setBackground(new java.awt.Color(19, 19, 19));
        jButton18.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton18ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(jButton17, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(0, 0, 0)
                .addComponent(jButton18, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(0, 0, 0))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton17, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton18, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 0, 0))
        );

        jPanel3.setBackground(new java.awt.Color(51, 51, 51));

        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });

        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });

        jButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton11ActionPerformed(evt);
            }
        });

        jButton12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton12ActionPerformed(evt);
            }
        });

        jButton13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton13ActionPerformed(evt);
            }
        });

        jButton14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton14ActionPerformed(evt);
            }
        });

        jButton15.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton15ActionPerformed(evt);
            }
        });

        jButton16.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton16ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addComponent(jButton13, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)
                .addGap(0, 0, 0)
                .addComponent(jButton14, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)
                .addGap(0, 0, 0)
                .addComponent(jButton15, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)
                .addGap(0, 0, 0)
                .addComponent(jButton16, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE))
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)
                .addGap(0, 0, 0)
                .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)
                .addGap(0, 0, 0)
                .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)
                .addGap(0, 0, 0)
                .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE))
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)
                .addGap(0, 0, 0)
                .addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)
                .addGap(0, 0, 0)
                .addComponent(jButton7, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)
                .addGap(0, 0, 0)
                .addComponent(jButton8, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE))
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jButton9, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)
                .addGap(0, 0, 0)
                .addComponent(jButton10, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)
                .addGap(0, 0, 0)
                .addComponent(jButton11, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)
                .addGap(0, 0, 0)
                .addComponent(jButton12, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)
                    .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)
                    .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)
                    .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE))
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)
                    .addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)
                    .addComponent(jButton7, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)
                    .addComponent(jButton8, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE))
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton9, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)
                    .addComponent(jButton10, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)
                    .addComponent(jButton11, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)
                    .addComponent(jButton12, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE))
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton13, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)
                    .addComponent(jButton14, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)
                    .addComponent(jButton15, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)
                    .addComponent(jButton16, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>                        

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        if(ca2==1){
                      jButton2.setDisabledIcon(a1);
                  }else if(ca2==2){
                      jButton2.setDisabledIcon(a2);
                  }else if(ca2==3){
                      jButton2.setDisabledIcon(a3);
                  }else if(ca2==4){
                      jButton2.setDisabledIcon(a4);
                  }else if(ca2==5){
                      jButton2.setDisabledIcon(a5);
                  }else if(ca2==6){
                      jButton2.setDisabledIcon(a6);
                  }else if(ca2==7){
                      jButton2.setDisabledIcon(a7);
                  }else if(ca2==8){
                      jButton2.setDisabledIcon(a8);
                  }
        jButton2.setEnabled(false);
        ganar();
        
        if(turno1 == 1 && turno2 == 0){
        btnact1 = jButton2;
        }else if(turno1 == 1 && turno2 == 1){
        btnact2 = jButton2;
        comprobar();
        turno1 = 0;
        turno2 = 0;
        }
    }                                        

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
      if(ca3==1){
                      jButton3.setDisabledIcon(a1);
                  }else if(ca3==2){
                      jButton3.setDisabledIcon(a2);
                  }else if(ca3==3){
                      jButton3.setDisabledIcon(a3);
                  }else if(ca3==4){
                      jButton3.setDisabledIcon(a4);
                  }else if(ca3==5){
                      jButton3.setDisabledIcon(a5);
                  }else if(ca3==6){
                      jButton3.setDisabledIcon(a6);
                  }else if(ca3==7){
                      jButton3.setDisabledIcon(a7);
                  }else if(ca3==8){
                      jButton3.setDisabledIcon(a8);
                  }
      jButton3.setEnabled(false);
      ganar();
      
      if(turno1 == 1 && turno2 == 0){
        btnact1 = jButton3;
        }else if(turno1 == 1 && turno2 == 1){
        btnact2 = jButton3;
        comprobar();
        turno1 = 0;
        turno2 = 0;
        }
    }                                        

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        if(ca4==1){
                      jButton4.setDisabledIcon(a1);
                  }else if(ca4==2){
                      jButton4.setDisabledIcon(a2);
                  }else if(ca4==3){
                      jButton4.setDisabledIcon(a3);
                  }else if(ca4==4){
                      jButton4.setDisabledIcon(a4);
                  }else if(ca4==5){
                      jButton4.setDisabledIcon(a5);
                  }else if(ca4==6){
                      jButton4.setDisabledIcon(a6);
                  }else if(ca4==7){
                      jButton4.setDisabledIcon(a7);
                  }else if(ca4==8){
                      jButton4.setDisabledIcon(a8);
                  }
        jButton4.setEnabled(false);
        ganar();
        
        if(turno1 == 1 && turno2 == 0){
        btnact1 = jButton4;
        }else if(turno1 == 1 && turno2 == 1){
        btnact2 = jButton4;
        comprobar();
        turno1 = 0;
        turno2 = 0;
        }
    }                                        

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {                                         
       if(ca6==1){
                      jButton6.setDisabledIcon(a1);
                  }else if(ca6==2){
                      jButton6.setDisabledIcon(a2);
                  }else if(ca6==3){
                      jButton6.setDisabledIcon(a3);
                  }else if(ca6==4){
                      jButton6.setDisabledIcon(a4);
                  }else if(ca6==5){
                      jButton6.setDisabledIcon(a5);
                  }else if(ca6==6){
                      jButton6.setDisabledIcon(a6);
                  }else if(ca6==7){
                      jButton6.setDisabledIcon(a7);
                  }else if(ca6==8){
                      jButton6.setDisabledIcon(a8);
                  }
       jButton6.setEnabled(false);
       ganar();
       
       if(turno1 == 1 && turno2 == 0){
        btnact1 = jButton6;
        }else if(turno1 == 1 && turno2 == 1){
        btnact2 = jButton6;
        comprobar();
        turno1 = 0;
        turno2 = 0;
        }
    }                                        

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        if(ca7==1){
                      jButton7.setDisabledIcon(a1);
                  }else if(ca7==2){
                      jButton7.setDisabledIcon(a2);
                  }else if(ca7==3){
                      jButton7.setDisabledIcon(a3);
                  }else if(ca7==4){
                      jButton7.setDisabledIcon(a4);
                  }else if(ca7==5){
                      jButton7.setDisabledIcon(a5);
                  }else if(ca7==6){
                      jButton7.setDisabledIcon(a6);
                  }else if(ca7==7){
                      jButton7.setDisabledIcon(a7);
                  }else if(ca7==8){
                      jButton7.setDisabledIcon(a8);
                  } 
        jButton7.setEnabled(false);
        ganar();
        
        if(turno1 == 1 && turno2 == 0){
        btnact1 = jButton7;
        }else if(turno1 == 1 && turno2 == 1){
        btnact2 = jButton7;
        comprobar();
        turno1 = 0;
        turno2 = 0;
        }
    }                                        

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        if(ca8==1){
                      jButton8.setDisabledIcon(a1);
                  }else if(ca8==2){
                      jButton8.setDisabledIcon(a2);
                  }else if(ca8==3){
                      jButton8.setDisabledIcon(a3);
                  }else if(ca8==4){
                      jButton8.setDisabledIcon(a4);
                  }else if(ca8==5){
                      jButton8.setDisabledIcon(a5);
                  }else if(ca8==6){
                      jButton8.setDisabledIcon(a6);
                  }else if(ca8==7){
                      jButton8.setDisabledIcon(a7);
                  }else if(ca8==8){
                      jButton8.setDisabledIcon(a8);
                  } 
        jButton8.setEnabled(false);
        ganar();
        
        if(turno1 == 1 && turno2 == 0){
        btnact1 = jButton8;
        }else if(turno1 == 1 && turno2 == 1){
        btnact2 = jButton8;
        comprobar();
        turno1 = 0;
        turno2 = 0;
        }
    }                                        

    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {                                          
                    if(ca10==1){
                      jButton10.setDisabledIcon(a1);
                  }else if(ca10==2){
                      jButton10.setDisabledIcon(a2);
                  }else if(ca10==3){
                      jButton10.setDisabledIcon(a3);
                  }else if(ca10==4){
                      jButton10.setDisabledIcon(a4);
                  }else if(ca10==5){
                      jButton10.setDisabledIcon(a5);
                  }else if(ca10==6){
                      jButton10.setDisabledIcon(a6);
                  }else if(ca10==7){
                      jButton10.setDisabledIcon(a7);
                  }else if(ca10==8){
                      jButton10.setDisabledIcon(a8);
                  }  
       jButton10.setEnabled(false);
       ganar();
       
       if(turno1 == 1 && turno2 == 0){
        btnact1 = jButton10;
        }else if(turno1 == 1 && turno2 == 1){
        btnact2 = jButton10;
        comprobar();
        turno1 = 0;
        turno2 = 0;
        }
    }                                         

    private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {                                          
        if(ca11==1){
                      jButton11.setDisabledIcon(a1);
                  }else if(ca11==2){
                      jButton11.setDisabledIcon(a2);
                  }else if(ca11==3){
                      jButton11.setDisabledIcon(a3);
                  }else if(ca11==4){
                      jButton11.setDisabledIcon(a4);
                  }else if(ca11==5){
                      jButton11.setDisabledIcon(a5);
                  }else if(ca11==6){
                      jButton11.setDisabledIcon(a6);
                  }else if(ca11==7){
                      jButton11.setDisabledIcon(a7);
                  }else if(ca11==8){
                      jButton11.setDisabledIcon(a8);
                  } 
        jButton11.setEnabled(false);
        ganar();
        
        if(turno1 == 1 && turno2 == 0){
        btnact1 = jButton11;
        }else if(turno1 == 1 && turno2 == 1){
        btnact2 = jButton11;
        comprobar();
        turno1 = 0;
        turno2 = 0;
        }
    }                                         

    private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {                                          
        if(ca12==1){
                      jButton12.setDisabledIcon(a1);
                  }else if(ca12==2){
                      jButton12.setDisabledIcon(a2);
                  }else if(ca12==3){
                      jButton12.setDisabledIcon(a3);
                  }else if(ca12==4){
                      jButton12.setDisabledIcon(a4);
                  }else if(ca12==5){
                      jButton12.setDisabledIcon(a5);
                  }else if(ca12==6){
                      jButton12.setDisabledIcon(a6);
                  }else if(ca12==7){
                      jButton12.setDisabledIcon(a7);
                  }else if(ca12==8){
                      jButton12.setDisabledIcon(a8);
                  }
        jButton12.setEnabled(false);
        ganar();
        
        if(turno1 == 1 && turno2 == 0){
        btnact1 = jButton12;
        }else if(turno1 == 1 && turno2 == 1){
        btnact2 = jButton12;
        comprobar();
        turno1 = 0;
        turno2 = 0;
        }
    }                                         

    private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {                                          
      if(ca14==1){
                      jButton14.setDisabledIcon(a1);
                  }else if(ca14==2){
                      jButton14.setDisabledIcon(a2);
                  }else if(ca14==3){
                      jButton14.setDisabledIcon(a3);
                  }else if(ca14==4){
                      jButton14.setDisabledIcon(a4);
                  }else if(ca14==5){
                      jButton14.setDisabledIcon(a5);
                  }else if(ca14==6){
                      jButton14.setDisabledIcon(a6);
                  }else if(ca14==7){
                      jButton14.setDisabledIcon(a7);
                  }else if(ca14==8){
                      jButton14.setDisabledIcon(a8);
                  }
      jButton14.setEnabled(false);
      ganar();
      
      if(turno1 == 1 && turno2 == 0){
        btnact1 = jButton14;
        }else if(turno1 == 1 && turno2 == 1){
        btnact2 = jButton14;
        comprobar();
        turno1 = 0;
        turno2 = 0;
        }
    }                                         

    private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) {                                          
        if(ca15==1){
                      jButton15.setDisabledIcon(a1);
                  }else if(ca15==2){
                      jButton15.setDisabledIcon(a2);
                  }else if(ca15==3){
                      jButton15.setDisabledIcon(a3);
                  }else if(ca15==4){
                      jButton15.setDisabledIcon(a4);
                  }else if(ca15==5){
                      jButton15.setDisabledIcon(a5);
                  }else if(ca15==6){
                      jButton15.setDisabledIcon(a6);
                  }else if(ca15==7){
                      jButton15.setDisabledIcon(a7);
                  }else if(ca15==8){
                      jButton15.setDisabledIcon(a8);
                  }   
        jButton15.setEnabled(false);
        ganar();
        
        if(turno1 == 1 && turno2 == 0){
        btnact1 = jButton15;
        }else if(turno1 == 1 && turno2 == 1){
        btnact2 = jButton15;
        comprobar();
        turno1 = 0;
        turno2 = 0;
        }
    }                                         

    private void jButton16ActionPerformed(java.awt.event.ActionEvent evt) {                                          
                  if(ca16==1){
                      jButton16.setDisabledIcon(a1);
                  }else if(ca16==2){
                      jButton16.setDisabledIcon(a2);
                  }else if(ca16==3){
                      jButton16.setDisabledIcon(a3);
                  }else if(ca16==4){
                      jButton16.setDisabledIcon(a4);
                  }else if(ca16==5){
                      jButton16.setDisabledIcon(a5);
                  }else if(ca16==6){
                      jButton16.setDisabledIcon(a6);
                  }else if(ca16==7){
                      jButton16.setDisabledIcon(a7);
                  }else if(ca16==8){
                      jButton16.setDisabledIcon(a8);
                  }     
        jButton16.setEnabled(false);
        ganar();
        
        if(turno1 == 1 && turno2 == 0){
        btnact1 = jButton16;
        }else if(turno1 == 1 && turno2 == 1){
        btnact2 = jButton16;
        comprobar();
        turno1 = 0;
        turno2 = 0;
        }
    }                                         

    private void jButton18ActionPerformed(java.awt.event.ActionEvent evt) {                                          
    inhabilitar();
    repartir(); 
    }                                         

    private void jButton17ActionPerformed(java.awt.event.ActionEvent evt) {                                          
      MenuPrincipal menu= new MenuPrincipal();
      menu.setVisible(true);
      this.dispose();
    }                                         

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
                if(ca1==1){
                    jButton1.setDisabledIcon(a1);
                }else if(ca1==2){
                    jButton1.setDisabledIcon(a2);
                }else if(ca1==3){
                    jButton1.setDisabledIcon(a3);
                }else if(ca1==4){
                    jButton1.setDisabledIcon(a4);
                }else if(ca1==5){
                    jButton1.setDisabledIcon(a5);
                }else if(ca1==6){
                    jButton1.setDisabledIcon(a6);
                }else if(ca1==7){
                    jButton1.setDisabledIcon(a7);
                }else if(ca1==8){
                    jButton1.setDisabledIcon(a8);
                } 
                jButton1.setEnabled(false);
                ganar();
                
                if(turno1 == 1 && turno2 == 0){
                btnact1 = jButton1;
                }else if(turno1 == 1 && turno2 == 1){
                btnact2 = jButton1;
                comprobar();
                turno1 = 0;
                turno2 = 0;
                }
    }                                        

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        if(ca5==1){
                      jButton5.setDisabledIcon(a1);
                  }else if(ca5==2){
                      jButton5.setDisabledIcon(a2);
                  }else if(ca5==3){
                      jButton5.setDisabledIcon(a3);
                  }else if(ca5==4){
                      jButton5.setDisabledIcon(a4);
                  }else if(ca5==5){
                      jButton5.setDisabledIcon(a5);
                  }else if(ca5==6){
                      jButton5.setDisabledIcon(a6);
                  }else if(ca5==7){
                      jButton5.setDisabledIcon(a7);
                  }else if(ca5==8){
                      jButton5.setDisabledIcon(a8);
                  }  
        jButton5.setEnabled(false);
        ganar();
        
        if(turno1 == 1 && turno2 == 0){
        btnact1 = jButton5;
        }else if(turno1 == 1 && turno2 == 1){
        btnact2 = jButton5;
        comprobar();
        turno1 = 0;
        turno2 = 0;
        }
    }                                        

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        if(ca9==1){
                      jButton9.setDisabledIcon(a1);
                  }else if(ca9==2){
                      jButton9.setDisabledIcon(a2);
                  }else if(ca9==3){
                      jButton9.setDisabledIcon(a3);
                  }else if(ca9==4){
                      jButton9.setDisabledIcon(a4);
                  }else if(ca9==5){
                      jButton9.setDisabledIcon(a5);
                  }else if(ca9==6){
                      jButton9.setDisabledIcon(a6);
                  }else if(ca9==7){
                      jButton9.setDisabledIcon(a7);
                  }else if(ca9==8){
                      jButton9.setDisabledIcon(a8);
                  }
        jButton9.setEnabled(false);
        ganar();
        
        if(turno1 == 1 && turno2 == 0){
        btnact1 = jButton9;
        }else if(turno1 == 1 && turno2 == 1){
        btnact2 = jButton9;
        comprobar();
        turno1 = 0;
        turno2 = 0;
        }
    }                                        

    private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {                                          
        if(ca13==1){
                      jButton13.setDisabledIcon(a1);
                  }else if(ca13==2){
                      jButton13.setDisabledIcon(a2);
                  }else if(ca13==3){
                      jButton13.setDisabledIcon(a3);
                  }else if(ca13==4){
                      jButton13.setDisabledIcon(a4);
                  }else if(ca13==5){
                      jButton13.setDisabledIcon(a5);
                  }else if(ca13==6){
                      jButton13.setDisabledIcon(a6);
                  }else if(ca13==7){
                      jButton13.setDisabledIcon(a7);
                  }else if(ca13==8){
                      jButton13.setDisabledIcon(a8);
                  }
        jButton13.setEnabled(false);
        ganar();
        
        if(turno1 == 1 && turno2 == 0){
        btnact1 = jButton13;
        }else if(turno1 == 1 && turno2 == 1){
        btnact2 = jButton13;
        comprobar();
        turno1 = 0;
        turno2 = 0;
        }
    }                                         

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Memoria.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Memoria.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Memoria.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Memoria.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new Memoria().setVisible(true);
            }
        });
        
    }
    
    public void ganar(){
        activos = 0;
        if(!jButton1.isEnabled()){
        activos++;
        oc = 1;
        }
        if(!jButton2.isEnabled()){
        activos++;
        oc = 2;
        }
        if(!jButton3.isEnabled()){
        activos++;
        oc = 3;
        }
        if(!jButton4.isEnabled()){
        activos++;
        oc = 4;
        }
        if(!jButton5.isEnabled()){
        activos++;
        oc = 5;
        }
        if(!jButton6.isEnabled()){
        activos++;
        oc = 6;
        }
        if(!jButton7.isEnabled()){
        activos++;
        oc = 7;
        }
        if(!jButton8.isEnabled()){
        activos++;
        oc = 8;
        }
        if(!jButton9.isEnabled()){
        activos++;
        oc = 9;
        }
        if(!jButton10.isEnabled()){
        activos++;
        oc = 10;
        }
        if(!jButton11.isEnabled()){
        activos++;
        oc = 11;
        }if(!jButton12.isEnabled()){
        activos++;
        oc = 12;
        }if(!jButton13.isEnabled()){
        activos++;
        oc = 13;
        }
        if(!jButton14.isEnabled()){
        activos++;
        oc = 14;
        }
        if(!jButton15.isEnabled()){
        activos++;
        oc = 15;
        }
        if(!jButton16.isEnabled()){
        activos++;
        oc = 16;
        }
        if(activos==16){JOptionPane.showMessageDialog(null,"","Ganaste!",JOptionPane.INFORMATION_MESSAGE, acertar);
        }
        
        if(activos%2 == 0){
        turno2 = 1;
        }else{
        turno1 = 1;
        }
      
        /*if(turno1 == 1 && turno2 == 0){System.out.println("Turno 1");}
        else if(turno1 == 1 && turno2 == 1){
       System.out.println("Turno 2"); 
        }*/
    }
    
     public void repartir(){
          for(i=1;i<9;i++){
              Random x=new Random();
              int pase=0;
              while(pase <2){
                int casilla=x.nextInt(16)+1;
              if(casilla==1 && !jButton1.isEnabled()){
                  ca1=i;
                  jButton1.setEnabled(true);
                pase++;
              }else if(casilla==2 && !jButton2.isEnabled()){
                  ca2=i;
                  jButton2.setEnabled(true);
                  pase++;
              }else if(casilla==3 && !jButton3.isEnabled()){
                  ca3=i;
                  jButton3.setEnabled(true);
                  pase++;
              }else if(casilla==4 && !jButton4.isEnabled()){
                  ca4=i;
                  jButton4.setEnabled(true);
                  pase++;
              }else if(casilla==5 && !jButton5.isEnabled()){
                  ca5=i;
                  jButton5.setEnabled(true);
                  pase++;
              }else if(casilla==6 && !jButton6.isEnabled()){
                  ca6=i;
                  jButton6.setEnabled(true);
                  pase++;
              }else if(casilla==7 && !jButton7.isEnabled()){
                  ca7=i;
                  jButton7.setEnabled(true);
                  pase++;
              }else if(casilla==8 && !jButton8.isEnabled()){
                  ca8=i;
                  jButton8.setEnabled(true);
                  pase++;
              }else if(casilla==9 && !jButton9.isEnabled()){
                  ca9=i;
                  jButton9.setEnabled(true);                  
                  pase++;
              }else if(casilla==10 && !jButton10.isEnabled()){
                  ca10=i;
                  jButton10.setEnabled(true);                 
                  pase++;
              }else if(casilla==11 && !jButton11.isEnabled()){
                  ca11=i;
                  jButton11.setEnabled(true);
                  pase++;
              }else if(casilla==12 && !jButton12.isEnabled()){
                  ca12=i;
                  jButton12.setEnabled(true);
                  pase++;
              }else if(casilla==13 && !jButton13.isEnabled()){
                  ca13=i;
                  jButton13.setEnabled(true);
                  pase++;
              }else if(casilla==14 && !jButton14.isEnabled()){
                  ca14=i;
                  jButton14.setEnabled(true);
                  pase++;
              }else if(casilla==15 && !jButton15.isEnabled()){
                  ca15=i;
                  jButton15.setEnabled(true);
                  pase++;
              }else if(casilla==16 && !jButton16.isEnabled()){
                  ca16=i;
                  jButton16.setEnabled(true);
                  pase++;
              }
              } 
          }
    }
     
     
     public void comprobar(){
         
         if((btnact1.getDisabledIcon() == a1 && btnact2.getDisabledIcon() == a1) || 
            (btnact1.getDisabledIcon() == a2 && btnact2.getDisabledIcon() == a2) || 
            (btnact1.getDisabledIcon() == a3 && btnact2.getDisabledIcon() == a3) || 
            (btnact1.getDisabledIcon() == a4 && btnact2.getDisabledIcon() == a4) || 
            (btnact1.getDisabledIcon() == a5 && btnact2.getDisabledIcon() == a5) || 
            (btnact1.getDisabledIcon() == a6 && btnact2.getDisabledIcon() == a6) || 
            (btnact1.getDisabledIcon() == a7 && btnact2.getDisabledIcon() == a7) || 
            (btnact1.getDisabledIcon() == a8 && btnact2.getDisabledIcon() == a8) ){
             //JOptionPane.showMessageDialog(null, "","",JOptionPane.INFORMATION_MESSAGE,acertar);
         }else{
             Timer timer = new Timer();
             timer.schedule(new TimerTask() { //Si tiene duda sobre esto 
             public void run() {              // es lo unico que pudimos
             btnact1.setEnabled(true);        // encontrar para que esperara
             btnact1.setDisabledIcon(null);   // despues de esconder los
                                              // botones, sin estar mostrando
             btnact2.setEnabled(true);        // un JOptionPane.showConfirmDialog
             btnact2.setDisabledIcon(null);   //con el que el usuario podria hacer
             }                                //trampa
             }, 125);
         }
     }
     
   public void inhabilitar(){
        jButton1.setEnabled(false);
        jButton2.setEnabled(false);
        jButton3.setEnabled(false);
        jButton4.setEnabled(false);
        jButton5.setEnabled(false);
        jButton6.setEnabled(false);
        jButton7.setEnabled(false);
        jButton8.setEnabled(false);
        jButton9.setEnabled(false);
        jButton10.setEnabled(false);
        jButton11.setEnabled(false);
        jButton12.setEnabled(false);
        jButton13.setEnabled(false);
        jButton14.setEnabled(false);
        jButton15.setEnabled(false);
        jButton16.setEnabled(false);
        ca1=0;ca2=0;ca3=0;ca4=0;
        ca5=0;ca6=0;ca7=0;ca8=0;
        ca9=0;ca10=0;ca11=0;ca12=0;
        ca13=0;ca14=0;ca15=0;ca16=0;
        jButton1.setIcon(null);
        jButton2.setIcon(null);
        jButton3.setIcon(null);
        jButton4.setIcon(null);
        jButton5.setIcon(null);
        jButton6.setIcon(null);
        jButton7.setIcon(null);
        jButton8.setIcon(null);
        jButton9.setIcon(null);
        jButton10.setIcon(null);
        jButton11.setIcon(null);
        jButton12.setIcon(null);
        jButton13.setIcon(null);
        jButton14.setIcon(null);
        jButton15.setIcon(null);
        jButton16.setIcon(null);
   }

    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton13;
    private javax.swing.JButton jButton14;
    private javax.swing.JButton jButton15;
    private javax.swing.JButton jButton16;
    private javax.swing.JButton jButton17;
    private javax.swing.JButton jButton18;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    // End of variables declaration                   
}